<template lang="html">
  <el-dialog :id="target"   :title="dialoginfo.title"
             @open="listenopen()"
             @close="close" :visible="dialoginfo.show">
    <el-form :id="target"  :model="dialoginfo.data" ref="dialoginfo" label-position="left">
      <div class="p-tb5">
        <el-alert
          title="温馨提示:"
          type="warning"
          description="只允许输入范围为0-999999999数值"
          :closable="false"
          show-icon>
        </el-alert>
      </div>
      <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                    prop="userName" label="账号" :label-width="formLabelWidth">
        <el-input :disabled="!isadd"  v-model="dialoginfo.data.userName" autocomplete="off" clearable/>
      </el-form-item>
      <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                    prop="balance" label="账户积分" :label-width="formLabelWidth">
        <el-input-number :controls="0" :min="0" precision="0" :max="999999999" v-model="dialoginfo.data.balance" autocomplete="off" clearable></el-input-number>
      </el-form-item>
      <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                    prop="freezeBalance" label="冻结积分" :label-width="formLabelWidth">
        <el-input-number :controls="0" :min="0"  precision="0" :max="999999999"  v-model="dialoginfo.data.freezeBalance" autocomplete="off" clearable></el-input-number>
      </el-form-item>
      <el-row>
        <el-form-item style="text-align: right">
          <el-button size="mini" @click="dialoginfo.data.show = false">取 消</el-button>
          <el-button size="mini" type="primary" @click="toAdd('dialoginfo')">保 存</el-button>
        </el-form-item>
      </el-row>
    </el-form>
  </el-dialog>
</template>
<script>
  export default {
    inject: ["reload"],
    data() {
      return {
        target: "userAssetadjust",
        formLabelWidth: '104px'
      }
    },
    props: ['dialoginfo'],
    methods: {
      listenopen() {
        if (this.isadd && this.$refs['dialoginfo'] != null) {
          this.$refs['dialoginfo'].resetFields();
        }
      },
      close() {
        this.$emit('changedialogshow');
      },
      toAdd(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            var t = {
              "id": this.dialoginfo.data.id,
                "balance": this.dialoginfo.data.balance,
                "freezeBalance": this.dialoginfo.data.freezeBalance,
            }
            this.$store.commit("saveLoadingMap", {"target": this.dialoginfo.url,id:this.target});
            this.proAPI.postJson(this.dialoginfo.url, t).then((res) => {
              this.$message.success({
                "message": res.message
              })
              setTimeout(()=>{
                this.reload();
              },1000)
            });
          } else {
            return false;
          }
        });
      }
    },
    updated() {
    },
    mounted() {
    }
  };
</script>
<style lang="css">
  #userage >>> .el-input-number .el-input__inner {
    text-align: left;
  }

  #userBaseInfoEdit >>> .el-dialog__body {
    padding: 15px 20px;
    color: #606266;
    font-size: 14px;
  }
</style>
